<template>
  <van-icon
      :color="value ? '#3296fa':'#777'"
      :name="value ? 'star':'star-o'"
      @click="Collection"
  />
</template>

<script>
import { deletCollection, AddCollection } from '@/api/user.js'
import { Toast } from 'vant'
export default {
  props: {
    value: {
      type: Boolean,
      require: true
    },
    artId: {
      // 对象 字符串 数字
      type: [Object, String, Number],
      require: true
    }
  },
  data () {
    return {
    }
  },

  created () {

  },

  methods: {
    async Collection () {
      Toast.loading({
        duration: 0, // 持续展示 toast
        forbidClick: true,
        message: '加载中...'
      })
      try {
        if (this.value) {
          await deletCollection(this.artId)
          Toast.success('取消收藏成功')
        } else {
          await AddCollection(this.artId)
          Toast.success('收藏成功')
        }
        this.$emit('input', !this.value)
      } catch (err) {
        console.dir(err)
        Toast.fail('收藏失败')
      }
    }
  }
}
</script>

<style scoped lang='less'>

</style>
